package controller

import (
	"exam/6.11/api/request"
	"exam/6.11/service"
	"github.com/gin-gonic/gin"
	"net/http"
)

type OtherController struct {
	service service.IOtherService
}

func NewOtherController(service service.IOtherService) *OtherController {
	return &OtherController{service: service}
}

func (o *OtherController) SupplierList(c *gin.Context) {
	var req request.Form
	err := c.ShouldBind(&req)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error:": "参数获取失败"})
		return
	}
	data := o.service.Find(c, &req)
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "成功", "data": data})
}
func (o *OtherController) SupplierCreate(c *gin.Context) {
	var req request.ProductForm
	err := c.ShouldBind(&req)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error:": "参数获取失败"})
		return
	}
	err = o.service.Add(c, &req)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{"error:": "失败" + err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "添加成功"})
}
